<?php
class CommentsController extends AppController {
	public $name = 'Comments';
	public $uses = 'Comment';
	
	public $components = array('Webservice.Webservice','RequestHandler');
	public $viewClass = 'Webservice.Webservice';
	
	function getCommentsByArticleId($id = null){
		//$this->RequestHandler->setContent('json', 'application/json');
		$comment = $this->Comment->getListCommentsByArticleId($id);
		$dataOutput = new Object();
		if(isset($comment)){
			$dataOutput->massage = null;
			$dataOutput->success = true;
			$dataOutput->response = $comment;
		}else{
			$dataOutput->massage = 'no database';
			$dataOutput->success = false;
		}
		$this->set(compact('dataOutput'));
	}
	
	function getCommentById($id = null){
		//$this->RequestHandler->setContent('json', 'application/json');
		$dataOutput = new Object();
		$comment = $this->Comment->getCommentById($id);
		//debug($comment);
		if(isset($comment)){
			$dataOutput->massage = null;
			$dataOutput->success = true;
			$dataOutput->response = $comment;
		}else{
			$dataOutput->massage = 'no database';
			$dataOutput->success = false;
		}
		$this->set(compact('dataOutput'));
	}
	function addNewComment($article_id = null,$title = null,$content = null,$user_id = null){
		if(isset($article_id) && isset($content)){
			if($this->Comment->addComment($user_id,$article_id,$title,$content)){
				$dataOutput->massage = 'save data successfuly!';
				$dataOutput->success = true;
			}else{
				$dataOutput->massage = 'add comment failed!';
				$dataOutput->success = false;
			}
		}else{
			$dataOutput->massage = 'saving failed!';
			$dataOutput->success = false;
		}
		$this->set(compact('dataOutput'));
	}
	
}
?>